﻿function SaveFilter(sTypeFilterName, sDefaultFilterName) {
    var filterName = window.prompt(sTypeFilterName, sDefaultFilterName);
    if (filterName != null && TrimString(filterName) != "") {
        document.getElementById("uiFilterName").value = TrimString(filterName);
        document.getElementById('uiFilterSave').click();
    }
}

function TrimString(s) {
    return s.replace(/^\s+|\s+$/g, "");
}

function SwitchFilterVisibility() {
    var ctlFilterRow = document.getElementById("uiFilterRow");
    var ctlHrRow = document.getElementById("uiHrRow");
    var ctlFilterDisplayStyle = document.getElementById("uiFilterDisplayStyle");
    if (ctlFilterRow == null || ctlHrRow == null || ctlFilterDisplayStyle == null)
        return;

    var isHidden = (ctlFilterRow.style.display == "none");
    ctlFilterRow.style.display = (isHidden) ? "" : "none";
    ctlHrRow.style.display = (isHidden) ? "" : "none";
    ctlFilterDisplayStyle.value = (isHidden) ? "" : "none";

    if (isHidden) {
        var sControlIdToFocus = document.getElementById("uiFirstFilterControlId").value;
        if (sControlIdToFocus != null && sControlIdToFocus != "") {
            var ctlToFocus = document.getElementById(sControlIdToFocus);
            if (ctlToFocus != null) {
                try { ctlToFocus.focus(); }
                catch (e) { }
            }
        }
    }
}

function Refresh() {
    document.getElementById("uiFilterSearch").click();
}

var iPendingRequestTimerId = null;

function DoAsyncPostBack() {
    // Only one request at a time allowed. Only one request in waiting list.
    var atlasManager = Sys.WebForms.PageRequestManager.getInstance();
    if (!atlasManager.get_isInAsyncPostBack()) {
        iPendingRequestTimerId = null;
        // Don't "enable all - disable some" if async request is fast. Otherwise the buttons may flash.
        setTimeout("EnableAllCommands();", 200);
        atlasManager._doPostBack("uiDoAsyncPostBackBtn", "");
    }
    else {
        if (iPendingRequestTimerId != null)
            clearTimeout(iPendingRequestTimerId);

        iPendingRequestTimerId = setTimeout("DoAsyncPostBack();", 500);
    }
}